﻿using System;
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.Hr;


namespace HengTong.ViewModel.Person.SysPersonResumeVms
{
    public partial class SysPersonResumeListVm : BasePagedListVM<SysPersonResumeView, SysPersonResumeSearcher>
    {
        protected override IEnumerable<IGridColumn<SysPersonResumeView>> InitGridHeader()
        {
            return new List<GridColumn<SysPersonResumeView>>
            {
                this.MakeGridHeader(x => x.PersonName),
                this.MakeGridHeader(x => x.TransferRequestName),
                this.MakeGridHeader(x => x.ResumeType),
                this.MakeGridHeader(x => x.StartDate),
                this.MakeGridHeader(x => x.EndDate),
                this.MakeGridHeader(x => x.OriginalGroupName),
                this.MakeGridHeader(x => x.OriginalPositionName),
                this.MakeGridHeader(x => x.OriginalDepartmentPosition),
                this.MakeGridHeader(x => x.OriginalRank),
                this.MakeGridHeader(x => x.OriginalBaseSalary),
                this.MakeGridHeader(x => x.OriginalPositionSalary),
                this.MakeGridHeader(x => x.OriginalPerformanceSalary),
                this.MakeGridHeader(x => x.NewGroupName),
                this.MakeGridHeader(x => x.NewPositionName),
                this.MakeGridHeader(x => x.NewDepartmentPosition),
                this.MakeGridHeader(x => x.NewRank),
                this.MakeGridHeader(x => x.NewBaseSalary),
                this.MakeGridHeader(x => x.NewPositionSalary),
                this.MakeGridHeader(x => x.NewPerformanceSalary),
                this.MakeGridHeader(x => x.TransferReason),
                this.MakeGridHeader(x => x.Remark),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysPersonResumeView> GetSearchQuery()
        {
            var query = DC.Set<SysPersonResume>()
                .CheckEqual(Searcher.PersonId, x => x.PersonId)
                .CheckEqual(Searcher.TransferRequestId, x => x.TransferRequestId)
                .CheckContain(Searcher.ResumeType, x => x.ResumeType)
                .CheckEqual(Searcher.OriginalGroupId, x => x.OriginalGroupId)
                .CheckEqual(Searcher.OriginalPositionId, x => x.OriginalPositionId)
                .CheckEqual(Searcher.NewGroupId, x => x.NewGroupId)
                .CheckEqual(Searcher.NewPositionId, x => x.NewPositionId)
                .Select(x => new SysPersonResumeView
                {
                    ID = x.ID,
                    PersonName = x.Person.Name,
                    TransferRequestName = x.TransferRequest.Approver,
                    ResumeType = x.ResumeType,
                    StartDate = x.StartDate,
                    EndDate = x.EndDate,
                    OriginalGroupName = x.OriginalGroup.GroupName,
                    OriginalPositionName = x.OriginalPosition.Name,
                    OriginalDepartmentPosition = x.OriginalDepartmentPosition,
                    OriginalRank = x.OriginalRank,
                    OriginalBaseSalary = x.OriginalBaseSalary,
                    OriginalPositionSalary = x.OriginalPositionSalary,
                    OriginalPerformanceSalary = x.OriginalPerformanceSalary,
                    NewGroupName = x.NewGroup.GroupName,
                    NewPositionName = x.NewPosition.Name,
                    NewDepartmentPosition = x.NewDepartmentPosition,
                    NewRank = x.NewRank,
                    NewBaseSalary = x.NewBaseSalary,
                    NewPositionSalary = x.NewPositionSalary,
                    NewPerformanceSalary = x.NewPerformanceSalary,
                    TransferReason = x.TransferReason,
                    Remark = x.Remark,
                })
                .OrderBy(x => x.StartDate ?? DateTime.MaxValue);
            return query;
        }
    }

    public class SysPersonResumeView : SysPersonResume
    {
        [Display(Name = "姓名")] public String PersonName { get; set; }
        [Display(Name = "审批人")] public String TransferRequestName { get; set; }
        [Display(Name = "_Admin.GroupName")] public String OriginalGroupName { get; set; }
        [Display(Name = "岗位名称")] public String OriginalPositionName { get; set; }
        [Display(Name = "_Admin.GroupName")] public String NewGroupName { get; set; }
        [Display(Name = "岗位名称")] public String NewPositionName { get; set; }

        [Display(Name = "原部门岗位", Description = "原部门和岗位的完整信息", GroupName = "原职位信息")]
        [StringLength(256)]
        public string OriginalDepartmentPosition { get; set; }

        [Display(Name = "新部门岗位", Description = "新部门和岗位的完整信息", GroupName = "调整后信息")]
        [StringLength(256)]
        public string NewDepartmentPosition { get; set; }
    }
}